<template>
	<view class="consume">
		<view class="consume-item" v-for="(item,index) in creditList" :key="index">
			<view class="consume-left">
				<view class="num">{{item.remark}}</view>
				<view class="time">{{item.create_at}}</view>
			</view>
			<view class="money">{{item.num}}</view>
		</view>
		<view class="consume-img" v-if="creditList.length==0">
			<image class="img" src="../../static/img/record.png" mode=""></image>
			<view class="text">
				暂无记录
			</view>
		</view>

	</view>
</template>

<script>
	import service from '@/store/service.js';
	export default {
		data() {
			return {
				creditList: [],
				isLoading: false,
				scroll: false,
				status: 0,
				pages: 1,
				limit: 2,
				page: 0,
				out: 0
			};
		},
		onLoad: function(vm) {
			if(vm.paytype){
				this.getMyCredit(vm.paytype);
					uni.setNavigationBarTitle({
								    title: "现金明细"
								});
			}else{
				this.getMyCredit();
			}
			
		},
		onReachBottom() {
			this.getMyCredit();
		},
		methods: {
			jump(url, id) {
				uni.navigateTo({
					url: url
				});
			},
			getMyCredit(vm) {
				var self = this;
				if (self.isLoading) {
					return;
				}
				if (self.page < self.pages) {
					self.out = 0;
					self.isLoading = true;
					self.scroll = false;
					self.status = 1;
					var page = self.page + 1;
					self.$http
						.post(service.api.balance.myCredit, {
							paytype:vm,
							page: page,
							type: 1
						})
						.then(function(res) {
							console.log(res);
							if (res.code == 1) {
								var list = res.data.data;
								if (list.length > 0) {
									list.forEach(item => {
										self.creditList.push(item);
									})
									self.pages = page + 1
								} else {
									self.pages = page;
								}
								self.page = page;
								self.scroll = true;
								self.isLoading = false;
								self.out = 1;
							}
						});
				}
			},
		}
	};
</script>

<style scoped>
	.consume-item {
		background-color: #fff;
		margin-top: 20upx;
		display: flex;
		justify-content: space-between;
		padding: 28upx 22upx 22upx;
	}

	.num {
		font-weight: bold;
	}

	.time {
		color: #999;
		font-size: 24upx;
		font-weight: 500;
	}

	.money {
		display: flex;
		align-items: center;
		color: #f81149;
	}

	.consume-img {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 296upx;
	}

	.img {
		width: 522upx;
		height: 350upx;
	}

	.text {
		color: #333;
		font-weight: bold;
	}
</style>
